package com.sunmi.reader.demo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;


public class MainActivity extends Activity {

    private ImageView next_step;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        next_step = (ImageView)findViewById(R.id.NEXT_STEP);
        next_step.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, CardControlActivity.class);
                startActivity(intent);
            }
        });

    }

    public static final String BytestoHexString(byte[] bArray, int len) {
        StringBuffer sb = new StringBuffer(len);
        String sTemp;

        for (int i=0; i<len; i++) {
            sTemp = Integer.toHexString(0xFF & bArray[i]);
            if (sTemp.length() < 2) sb.append(0);
            sb.append(sTemp.toUpperCase());
        }

        return sb.toString();
    }

    public static final String BytestoASCII(byte[] data, int len) {
        int          i;
        int          j;
        StringBuffer tStringBuf = new StringBuffer();

        char[] tChars = new char[len];

        for (i=0; i<len; i++) {
            tChars[i] = (char) data[i];
        }

        tStringBuf.append(tChars);

        return tStringBuf.toString();
    }

    public static final byte[] HexStringtoBytes(String hexString) {
        hexString = hexString.toLowerCase();
        final byte[] byteArray = new byte[hexString.length() / 2];
        int k = 0;
        for (int i = 0; i < byteArray.length; i++) {//因为是16进制，最多只会占用4位，转换成字节需要两个16进制的字符，高位在先
            byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 0xff);
            byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 0xff);
            byteArray[i] = (byte) (high << 4 | low);
            k += 2;
        }
        return byteArray;
    }

}
